import java.awt.Graphics;
import java.awt.Image;
import java.util.Scanner;

import javax.swing.JFrame;
import javax.swing.JPanel;

import resources.ResMgr;
import resources.ResRO;
import resources.Sprite;
import utils.MyException;
import utils.OOBB;

class Main extends JFrame {

	private static ResRO r;
	private int i = 0;
	volatile boolean running = true;

	public Main() {
		setVisible(true);
		setSize(320, 320);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		add(new JPanel() {

			@Override
			public void paint(Graphics g) {
				g.drawImage(((Sprite) r).get(i, OOBB.REVERSE), 0, 0, 32, 32, null);
			}

		});
	}

	public static void main(String[] args) throws MyException, InterruptedException {

		ResMgr.get().open("img.bg.Menu");
		r = ResMgr.get().get("Menu");
		final Main f = new Main();
		final Thread th1 = new Thread() {
			public void run() {
				while (true)
					while (f.running) {
						try {
							Thread.sleep(500);
							f.repaint();
							f.i++;
						} catch (InterruptedException e) {}
					}
			}
		};
		final Scanner s = new Scanner(System.in);
		Thread th2 = new Thread() {
			public void run() {
				while (true)
					while (s.hasNext()) {
						if (s.nextLine().equals("stop"))
							f.running = false;
						else if (s.nextLine().equals("start"))
							f.running = true;
					}
			}
		};
		th1.start();
		Thread.sleep(2000);
		f.stop();
	}

	private void stop() {
		running = false;
	}
	
}
